window.onload = function(){
	loadCartData();	
}


function loadCartData(){
	var d = new dquery();
	d.get("LoadOrder", function(data){
		if(data != ""){
			var result = JSON.parse(data);
			for(var i=0;i<result.length;i++){
				var line = result[i].menulist;
				var time = result[i].ctime;
				var order = new Cart();
				order.showorder(line);
				cartTable(order,time);
			}			
		}		
	});
}

function cartTable(cart,time){
	var dc = document.getElementById("cartlist");	
	var tb = document.createElement("div");
	tb.setAttribute('class','cmenu');
	for(var i=0;i<cart.size();i++){
		if(cart.cartList[i].num != 0){
			var tr = document.createElement("div");
			tr.setAttribute('id',i);
			tr.setAttribute('class','row');
			var icon = document.createElement("img");
			icon.setAttribute('src',cart.cartList[i].getDish().getIcon());
			var tit = document.createElement("p");
			tit.setAttribute('class','name');
			var val = document.createElement("p");
			val.setAttribute('class','price');			
			var num = document.createElement("p");
			tit.innerText=cart.cartList[i].getDish().getName();
			val.innerText="Price : "+cart.cartList[i].getDish().getPrice();			
			num.innerText="Number : "+cart.cartList[i].num;
			var intime = document.createElement("p");
			intime.innerText = "Order time : "+time;
			
			tr.appendChild(icon);
			tr.appendChild(tit);
			tr.appendChild(num);
			tr.appendChild(val);
			tr.appendChild(intime);
			tb.appendChild(tr);	
		}		
	}
	dc.appendChild(tb);	
}
